#include <windows.h>
#include "CFindItemPacket.h"

// Monster drops gil
CFindItemPacket::CFindItemPacket(unsigned int gilQuantity, CBaseEntity * pEntity) {
	memset(this->data, 0, 0x1E*2);
	this->type = 0xD2;
	this->size = 0x1E;
	
	unsigned short targID = pEntity->getTargId();
	unsigned int ID = pEntity->getId();
	memcpy(this->data+0x08-0x04, &ID, 4);
	memcpy(this->data+0x12-0x04, &targID, 2);
	memcpy(this->data+0x0C-0x04, &gilQuantity, 4);
	// slot 11 will never be used, so its safe to put money here
	this->data[0x14-0x04] = 0x0B; 
}

// Monster drops an item
CFindItemPacket::CFindItemPacket(unsigned short itemID, unsigned int itemQuantity, unsigned int timeStamp, unsigned char slotID, CBaseEntity * pEntity) {
	memset(this->data, 0, 0x1E*2);
	this->type = 0xD2;
	this->size = 0x1E;
	unsigned short targID = pEntity->getTargId();
	unsigned int ID = pEntity->getId();
	memcpy(this->data+0x08-0x04, &ID, 4);
	memcpy(this->data+0x12-0x04, &targID, 2);
	memcpy(this->data+0x04-0x04, &itemQuantity, 4);
	memcpy(this->data+0x10-0x04, &itemID, 2);
	memcpy(this->data+0x19-0x04, &timeStamp, 4);

	this->data[0x14-0x04] = slotID; 
}

// Player joins a treasure pool to see an item
CFindItemPacket::CFindItemPacket(unsigned short itemID, unsigned int itemQuantity, unsigned int timeStamp, unsigned char slotID) {
	memset(this->data, 0, 0x1E*2);
	this->type = 0xD2;
	this->size = 0x1E;
	memcpy(this->data+0x04-0x04, &itemQuantity, 4);
	memcpy(this->data+0x10-0x04, &itemID, 2);
	memcpy(this->data+0x19-0x04, &timeStamp, 4);

	this->data[0x14-0x04] = slotID; 
}

// used to clear the client treasure pool
CFindItemPacket::CFindItemPacket(unsigned char slotID) {
	memset(this->data, 0, 0x1E*2);
	this->type = 0xD2;
	this->size = 0x1E;

	this->data[0x14-0x04] = slotID;
}

CFindItemPacket::~CFindItemPacket() {

}
